package com.aurora.source.center.presenter;

import android.content.Context;

import com.aurora.source.base.BaseBean;
import com.aurora.source.base.BasePresenter;
import com.aurora.source.center.bean.FlowDataBean;
import com.aurora.source.center.bean.PersonFlowBean;
import com.aurora.source.center.view.SourceCenterMainView;
import com.aurora.source.constant.AuroraConstants;
import com.aurora.source.util.netutil.SubscriberObserver;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ww
 * @description:
 * @date: 2018/9/21
 */
public class SourceCenterMainPresenter extends BasePresenter<SourceCenterMainView>{
    public SourceCenterMainPresenter(SourceCenterMainView baseView) {
        super(baseView);
    }

    public void getFlowInfo(String userId) {
        requestMethod.getFlowInfo(userId, new SubscriberObserver<BaseBean<FlowDataBean>>((Context) baseView, "数据加载中...") {

            @Override
            public void onSuccess(BaseBean<FlowDataBean> flowDataBeanBaseBean) {

                if(flowDataBeanBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)){
                    List<PersonFlowBean> personFlowBeans = new ArrayList<>();

                    List<FlowDataBean.CompanyProcessListBean> companyProcessList = flowDataBeanBaseBean.getData().getCompanyProcessList();
                    List<FlowDataBean.UserProcessListBean> userProcessList = flowDataBeanBaseBean.getData().getUserProcessList();

                   // boolean notSelect = true;
                    for(FlowDataBean.CompanyProcessListBean e:companyProcessList){
                        PersonFlowBean personFlowBean = new PersonFlowBean();
                        personFlowBean.setProcessNumber(e.getProcessNumber());
                        personFlowBean.setFlowId(e.getProcessId());
                        personFlowBean.setFlowName(e.getProcessTitle());
                        personFlowBean.setHavaPermision(false);
                        for(FlowDataBean.UserProcessListBean m:userProcessList){
                            if(e.getProcessId().equals(m.getProcessId())){//有权限
                                personFlowBean.setHavaPermision(true);
                                /*if(notSelect){
                                    personFlowBean.setSelect(true);
                                    notSelect = false;
                                }*/
                            }
                        }
                        personFlowBeans.add(personFlowBean);
                    }
                    baseView.onGetFlowSuccess(personFlowBeans);
                }else {
                    baseView.onGetFlowFail(flowDataBeanBaseBean.getMsg());
                }

            }

            @Override
            public void onError(String msg) {
                baseView.onGetFlowFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }
}
